
<template src="./tpl.html"></template>
<script>
import {
  CONSENT_GET_ROLE_LIST,
  CONSENT_SAVE_ROLE,
  CONSENT_DELETE_ROLE,
  CONSENT_GET_ZK_LIST,
} from "_SERVICES/api";
import { trimAll } from "UTILS/string";
import { isvalidateNum2 } from "UTILS/validate";
import { timeFormatter } from "UTILS/format";

import { getStorage, getAllRouterId } from "UTILS/util";

import page from "@/modules/CST/mxins/page";
export default {
  name: "role",
  mixins: [page],

  data() {

  
    return {
      formInline: {
        ROLE_NAME: "",
      },
      dialogVisible: false,
      ymqx_list: [],
      editInfo: {
        YMQX:[],
        ZKQX:[]
      },
      saveLoading: false,
      rules: {
        ROLE_NAME: [
          { required: true, message: "请输入角色名称", trigger: "blur" },
        ],
        YMQX: [
          { required: true, message: "请选择页面权限", trigger: "change" },

        ],
        ZKQX: [
          { required: true, message: "请选择专科权限", trigger: "change" },

        ],
      },

      headers: [
        {
          label: "ID",
          prop: "ROLE_ID",
        },
        {
          label: "角色名称",
          prop: "ROLE_NAME",
        },
        {
          label: "状态",
          prop: "ZTBZ_MC",
        },
      ],
      ZK_LIST: [],
      checked: false
    };
  },
  created() {
    this.get_zkid_list();
    this.ymqx_list = getAllRouterId();
    this.getList();

    console.log(this.ymqx_list);
  },
  mounted() {},
  methods: {
    getList() {
      this.listLoading = true;
      let params = {
        ...this.formInline,
      };
      Object.assign(params, this.getParams());

      return CONSENT_GET_ROLE_LIST(params)
        .then((res) => {
          this.listLoading = false;
          this.listQuery.totalNum = res.totalNum;
          this.tableData = res.data;
        })
        .catch((res) => {
          this.tableData = [];
          this.listLoading = false;
          this.downloadLoading = false;
      });
    },
    get_zkid_list() {
      CONSENT_GET_ZK_LIST({}).then((res) => {
        console.log("获取专科列表成功");
        this.ZK_LIST = res.data || [];
      });
    },
    changeSelect(value){
      if(value) {
        let ids = []
        this.ymqx_list.forEach((item)=>{
          ids.push(item.ID)
        })
        this.$set(this.editInfo,'YMQX',ids)

      }else{
        this.$set(this.editInfo,'YMQX',[])

      }
    },
    add() {
      this.dialogVisible = true;
      this.editInfo = {
        YMQX:[],
        ZKQX:[]
      };
    },
    editRow(row) {
      this.dialogVisible = true;
      this.editInfo = { ...row };
    },
    sure() {
      console.log(this.editInfo);
      this.$refs["buildData"].validate((valid) => {
        if (valid) {
        
          this.saveLoading = true;
          CONSENT_SAVE_ROLE({
            ROLE_ID: this.editInfo.ROLE_ID || '',
            ROLE_NAME: this.editInfo.ROLE_NAME,
            YMQX: this.editInfo.YMQX,
            ZKQX: this.editInfo.ZKQX,

          })
            .then((res) => {
              this.saveLoading = false;
              this.dialogVisible = false;
              this.$message.success("操作成功");
              this.getList();
            })
            .catch((e) => {
              this.saveLoading = false;
          });
        }
      });
    },
    deleteRow(row) {
      this.$confirm("确定要暂停此角色吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          CONSENT_DELETE_ROLE({
            ROLE_ID: row.ROLE_ID,
          }).then((res) => {
            this.$message.success("暂停成功");
            this.getList();
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="less">
</style>
